<template>
  <div class="deviceKeep">
    <van-nav-bar title="设备保养列表" left-arrow @click-left="goBack()"></van-nav-bar>
    <!-- <van-cell title="设备编号">
			<van-dropdown-menu>
			  <van-dropdown-item v-model="value1" :options="option1" @change="getAllInfo"/>
			</van-dropdown-menu>
		</van-cell> -->
    <div class="radio">
      <van-radio-group v-model="radio">
        <van-cell-group>
          <van-cell title-class='title' title="正常" clickable @click="radio = '1'">
            <van-radio slot="right-icon" name="1" checked-color='rgb(103, 177, 251)' />
          </van-cell>
          <van-cell title-class='title' title="超时" clickable @click="radio = '2'">
            <van-radio slot="right-icon" checked-color='rgb(103, 177, 251)' name="2" />
          </van-cell>

        </van-cell-group>
      </van-radio-group>
    </div>
    <device-list v-show="overtime" @goNext="goKeepInfo" :deviceList="overTimeDeviceList" :display="display"></device-list>
    <device-list v-show="!overtime" @goNext="goKeepInfo" :deviceList="normalDeviceList" :display="display"></device-list>

    </div>
  </div>
</template>

<script>
  import moment from 'moment'
  import deviceList from "../subcom/deviceList.vue";
  export default {
    data() {
      return {
        unfinishList: [],
        overtime: true,
        radio: '1',
        value1: 0,
        option1: [],
        showkeywords: false,
        displayAdd: true,
        display: this.$route.params.display,
        overTimeDeviceList:[],//超时数据
        normalDeviceList:[],//正常数据
        deviceList: [],
        display: false
      };
    },
    created() {
      this.getDevice();

    },
    watch: {
      radio(newVal) {
        if (newVal == '1') {
          this.overtime = true
        } else if (newVal == '2') {
          this.overtime = false
        }
      }
    },
    methods: {
      toFinish(item, i) {
        this.$axios.post('/Repair/updateRepair.do', {
          curcontent: item.curcontent,
          cycle: item.cycle,
          planrepairtime: item.planrepairtime,
          prerepairtime: item.prerepairtime,
          rfacilityid: item.facilityname
        }).then(res => {
          if (res.status === 200) {
            Toast.success({
              message: '保养成功',
              duration: 900
            })
          }
        })
      },


      getDevice() {
        this.deviceList = []
        var nowDate = new Date()
        this.$axios.post("Repair/selectAllRepair.do").then(res => {
          if (res.data.status === 200) {
             this.deviceList = this.getOnly(res.data.msg);
             // console.log(this.deviceList)
             this.deviceList.map((value,index)=>{
               var getTime = new Date(value.planRepairTime)

               if(nowDate < getTime){
                 this.overTimeDeviceList.push(value)

               }else {
                 this.normalDeviceList.push(value)

               }
             })

          }
        });
      },
      goKeepInfo(facilityname) {
        this.$router.push({
          name: "keepRecord",
          params: {
            facilityname: facilityname
          }
        });
      },

      getOnly(list) {
        let newData = [];

        list.map((value, index) => {
          if (value.rUserName) {
            newData.push({
              id: value.id,
              facilityname: value.facilityname,
              planRepairTime: value.planRepairTime

            });
            this.option1.push({
              text: value.facilityname,
              value: value.facilityname
            });
          } else if (!value.rUserName) {
            this.unfinishList.push(value)
          }
        });

        var arrays = newData;
        var result = [];
        var obj = [];

        var str;

        for (var i = 0; i < arrays.length; i++) {
          str = JSON.stringify(arrays[i]);

          if (obj.indexOf(str) == -1) {
            result.push(arrays[i]);

            obj.push(str);
          }
        }

        return result;
      }
    },
    components: {
      deviceList
    }
  };
</script>

<style scoped="scoped">
  .van-dropdown-menu {
    height: 1.25rem;
    line-height: 1.25rem;
  }

  img {
    vertical-align: middle;
    width: 1.1rem;
    height: 1.1rem;
  }

  .cellTitle {
    width: 5.625rem;
    flex: 1;
  }

  .cellValue {
    text-align: left;
    flex: 3;
  }

  .van-dropdown-menu {
    height: 1.25rem;
    line-height: 1.25rem;
  }

  .toRepair {
    display: flex;
    justify-content: center;
    border-top: 1px solid #EEEEEE;
    font-size: .8rem;
    color: red;
    padding-top: .5rem;
  }

  .van-radio-group {
    margin-top: 1rem;
  }

  .title {
    color: #222222;
  }

  .van-button {
    color: #777;
  }

  .van-button--default {
    border: none;
  }

  .keywords {
    font-size: 0.8rem;
    color: #999999;
    margin-bottom: 0.8rem;
  }

  .numCell {
    padding-bottom: .5rem;
    border-bottom: 1px solid #EEEEEE;
  }

  .num {
    font-size: .9rem;
    color: #222;
    font-weight: bold;
  }

  .van-cell {
    padding: .3rem 1rem !important;
    color: #969799;
  }

  .repairCard {
    padding: .6rem;
    margin-top: .5rem;
  }

  .info {
    margin-bottom: .3rem;
    padding: .6rem;
  }

  .cell-info {
    box-shadow: 2px 2px 5px #ADADAD;
    padding-bottom: .8rem;
  }
</style>
